//
//  BranchStoreTableViewController.m
//  OrderMeal
//
//  Created by 江苏宏创 on 14-7-21.
//  Copyright (c) 2014年 qkong. All rights reserved.
//

#import "BranchStoreTableViewController.h"
#import "Protocols.h"
#import "SendHttpOperation.h"
@interface BranchStoreTableViewController ()<PassRegionProtocol>{
    NSMutableArray *tableData;
}

@end

@implementation BranchStoreTableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //下拉刷新
    UIRefreshControl *refreshControl = [[UIRefreshControl alloc]init];
    [refreshControl addTarget:self action:@selector(refreshTableView) forControlEvents:UIControlEventValueChanged];
    self.refreshControl = refreshControl;
    NSLog(@"size--->%@",NSStringFromCGRect(self.refreshControl.frame));
    tableData = [[NSMutableArray alloc]init];
    
    [self.tableView setContentOffset:CGPointMake(0, -60.0f) animated:YES];
    [self.refreshControl beginRefreshing];
    
    [SendHttpOperation sharedHttpOperation].passRegionDelegate = self;
    [[SendHttpOperation sharedHttpOperation] getRegions:self];
    
    //去除底部多余
    self.tableView.tableFooterView = [[UIView alloc]init];
}

-(void)refreshTableView{
    [[SendHttpOperation sharedHttpOperation] getRegions:self];
}


-(void)passRegions:(NSMutableArray *)regions{
    dispatch_async(dispatch_get_main_queue(), ^{
        tableData = regions;
        [self.tableView reloadData];
    });
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return tableData.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"regionCell" forIndexPath:indexPath];
    
    // Configure the cell...
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"regionCell"];
    }
    
    cell.textLabel.text = tableData[indexPath.row][@"name"];
    cell.imageView.image = [UIImage imageNamed:@"collection.jpg"];
    
    
    return cell;
}


@end
